/* $Id: ListViewHelper.java 85 2007-12-20 06:50:58Z osborn.steven $
 * 
 * Undroid Package Manager
 *
 * Copyright 2007 Steven Osborn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.bitsetters.android.common;

import android.app.ListActivity;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.MeasureSpec;
import android.widget.TextView;

import com.bitsetters.undroid.R;

/**
 * 
 * @author Steven Osborn - http://steven.bitsetters.com
 */
public class ListViewHelper {
    
    /**
     * Add stripes to the list view.
     */
    public static void setupListStripes(ListActivity a) {
        // Get Drawables for alternating stripes
        Drawable[] lineBackgrounds = new Drawable[2];

        lineBackgrounds[0] = a.getResources().getDrawable(R.drawable.even_stripe);
        lineBackgrounds[1] = a.getResources().getDrawable(R.drawable.odd_stripe);

        // Make and measure a sample TextView of the sort our adapter will
        // return
        View view = a.getViewInflate().inflate(
                android.R.layout.simple_list_item_1, null, null);
        
        TextView v = (TextView) view.findViewById(android.R.id.text1);
        v.setText("X");
        // Make it 100 pixels wide, and let it choose its own height.
        v.measure(MeasureSpec.makeMeasureSpec(View.MeasureSpec.EXACTLY, 100),
                MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, 0));
        int height = v.getMeasuredHeight();
        a.getListView().setStripes(lineBackgrounds, height);
    }
    
}
